package com.whnk.web.controller.pm;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.whnk.common.annotation.Log;
import com.whnk.common.base.AjaxResult;
import com.whnk.common.enums.BusinessType;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.pm.domain.SusdDetail;
import com.whnk.pm.service.ISusdDetailService;

/**
 * 补助明细 信息操作处理
 * 
 * @author whwhnk
 * @date 2019-07-24
 */
@Controller
@RequestMapping("/pm/susdDetail")
public class SusdDetailController extends BaseController
{
    private String prefix = "pm/susdDetail";
	
	@Autowired
	private ISusdDetailService susdDetailService;
	
	@RequiresPermissions("pm:susdDetail:view")
	@GetMapping()
	public String susdDetail()
	{
	    return prefix + "/susdDetail";
	}
	
	/**
	 * 查询补助明细列表
	 */
	@RequiresPermissions("pm:susdDetail:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SusdDetail susdDetail)
	{
		startPage();
        List<SusdDetail> list = susdDetailService.selectSusdDetailList(susdDetail);
		return getDataTable(list);
	}
	
	/**
	 * 新增补助明细
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存补助明细
	 */
	@RequiresPermissions("pm:susdDetail:add")
	@Log(title = "补助明细", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(SusdDetail susdDetail)
	{		
		susdDetail.setUpdateBy(getLoginName());
		return toAjax(susdDetailService.insertSusdDetail(susdDetail));
	}

	/**
	 * 修改补助明细
	 */
	@GetMapping("/edit/{sudeId}")
	public String edit(@PathVariable("sudeId") Integer sudeId, ModelMap mmap)
	{
		SusdDetail susdDetail = susdDetailService.selectSusdDetailById(sudeId);
		mmap.put("susdDetail", susdDetail);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存补助明细
	 */
	@RequiresPermissions("pm:susdDetail:edit")
	@Log(title = "补助明细", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(SusdDetail susdDetail)
	{		
		susdDetail.setUpdateBy(getLoginName());
		return toAjax(susdDetailService.updateSusdDetail(susdDetail));
	}
	
	/**
	 * 删除补助明细
	 */
	@RequiresPermissions("pm:susdDetail:remove")
	@Log(title = "补助明细", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(susdDetailService.deleteSusdDetailByIds(ids));
	}
	
	/**
	 * 查看详细信息
	 * 
	 * @param sudeId
	 * @param mmap
	 * @return
	 */
	@RequiresPermissions("pm:susdDetail:detail")
    @GetMapping("/detail/{sudeId}")
    public String detail(@PathVariable("sudeId") Integer sudeId, ModelMap mmap)
	{
		SusdDetail susdDetail = susdDetailService.selectSusdDetailById(sudeId);
		mmap.put("susdDetail", susdDetail);
        return prefix + "/detail";
    }
}
